﻿create or replace function public.sort_distinct(anyarray) returns anyarray as $$
/*
   Sort array of type varchar and return unique elements
   See also http://postgresql.1045698.n5.nabble.com/array-sort-for-varchar-arrays-td1884543.html
   USAGE:
   select sort_distinct('{10,3,6,10}'::int[])    >>> {3,6,10}
   select sort_distinct('{10,3,6,10}'::text[])   >>> {10,3,6}   
*/
    select array(select distinct $1[i] from generate_series(array_lower($1,1),
    array_upper($1,1)) g(i) order by 1)
$$ language sql strict immutable; 